<?php
require_once '../includes/functions.php';
check_login();

$template_name = $_GET['template'] ?? '';
$template_path = '';
$html_content = '';

if ($template_name) {
    $template_path = get_template_path($template_name);
    if (file_exists($template_path . '/index.html')) {
        $html_content = file_get_contents($template_path . '/index.html');
    }
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>模板编辑器 - 落地页管理系统</title>
    <link rel="stylesheet" href="css/admin.css">
    <link rel="stylesheet" href="css/editor.css">
    <script src="js/ace/ace.min.js"></script>
    <script src="js/ace/theme-monokai.min.js"></script>
    <script src="js/ace/mode-html.min.js"></script>
    <script src="js/ace/ext-language_tools.js"></script>
    <script src="js/ace/ext-searchbox.js"></script>
    <script src="js/editor.js"></script>
</head>
<body>
    <div class="admin-container">
        <div class="sidebar">
            <div class="sidebar-header">
                <h2>落地页管理系统</h2>
            </div>
            <ul class="sidebar-menu">
                <li><a href="index.php">仪表盘</a></li>
                <li><a href="create_subdomain.php">创建落地页</a></li>
                <li><a href="logout.php">退出登录</a></li>
            </ul>
        </div>

        <div class="main-content"></div>

        <script>
            new Editor({
                editorTitle: '模板编辑器',
                initialContent: <?php echo json_encode($html_content, JSON_UNESCAPED_UNICODE); ?>,
                templateName: '<?php echo htmlspecialchars($template_name); ?>'
            });
        </script>
    </div>
</body>
</html>
